function pe14(limit) {
    
    var stepList = [];
    stepList[1] = 1;
    
    var getStepCount = function(number) {
        if(stepList[number]) return stepList[number];
        if(number%2==0) {
            stepList[number] = getStepCount(number/2) + 1;
            return stepList[number];
        } else {
            stepList[number] = getStepCount(number*3+1) + 1;
            return stepList[number];
        }
    }
    
    var step, maxStep = 0, low=Math.floor(limit/2)+1;
    for(var i=limit; i>=low; i--) {
        step = getStepCount(i);
        if(step > maxStep) {
            maxStep = step;
            print(i + "::" + step);
        }
    }
}

var t = new Date().getTime();
pe14(1000000);
print("Time used: " + (new Date().getTime()-t)/1000 + "s");

